using YatFram.UnitTesting;

namespace Examples.UnitTestATM
{
    public class AutomatedTellerMachineBuilder : IBuilder<AutomatedTellerMachine>
    {
        private IAccountRepository _accountRepository;

        public static implicit operator AutomatedTellerMachine(AutomatedTellerMachineBuilder builder)
        {
            return builder.Build();
        }

        public AutomatedTellerMachine Build()
        {
            return new AutomatedTellerMachine(_accountRepository);
        }

        public IBuilder<AutomatedTellerMachine> With<T>(IFake<T> service)
        {
            if (service is IAccountRepository)
            {
                return With((IAccountRepository) service);
            }
            return this;

        }

        public AutomatedTellerMachineBuilder With(IAccountRepository accountRepository)
        {
            _accountRepository = accountRepository;
            return this;
        }
    }
}